const mongoose = require('mongoose');
const validator = require('validator');
const columnSchema = new mongoose.Schema(
  {
    // name: {
    //   type: String,
    //   required: [true, 'Please tell  us your column name'],
    // },
    textHtml: {
      type: String,
      required: [true, 'Please provide the textHtml'],
    },
    imgList: {
      type: Array,
      default: [],
    },
    createAt: {
      type: Date,
      default: Date.now(),
    },

    active: {
      type: Boolean,
      default: true,
      select: false,
    },
    user: {
      type: mongoose.Schema.ObjectId,
      ref: 'User',
      required: [true, 'Column must belong to a user'],
    },
  },
  {
    toJSON: { virtuals: true },
    toObject: { virtuals: true },
  }
);
columnSchema.pre(/^find/, function (next) {
  this.find({ active: { $ne: false } });
  next();
});
columnSchema.pre(/^find/, function (next) {
  this.populate({
    path: 'user',
    select: 'name photo',
  });
  next();
});
const Column = mongoose.model('Column', columnSchema);

module.exports = Column;
